﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace FileTrays
{
    public partial class FileInboxConfigControl : Form
    {
        private FileInbox _inbox;
        public FileInboxConfigControl(FileInbox inbox)
        {
            InitializeComponent();
            _inbox = inbox;
            textBoxName.Text = _inbox._concreteName;
            txtFilePath.Text = _inbox.folder;
        }

        private void btnPath_Click(object sender, EventArgs e)
        {
            SelectDirectory();
        }

        private void SelectDirectory()
        {
            DialogResult txtFileDirectory = txtFolderBrowserDialog.ShowDialog();
            if (txtFileDirectory == DialogResult.OK)
            {
                //_inbox.folder = txtFolderBrowserDialog.SelectedPath;
                txtFilePath.Text = txtFolderBrowserDialog.SelectedPath;
            }
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnAceptar_Click(object sender, EventArgs e)
        {
            bool validName = textBoxName.Text != "";
           /* bool validPath = (txtFolderBrowserDialog.SelectedPath != "" && Directory.Exists(txtFolderBrowserDialog.SelectedPath));
            validPath |= (txtFilePath.Text != "" && Directory.Exists(txtFilePath.Text));*/
            bool validPath = (txtFilePath.Text != "" && Directory.Exists(txtFilePath.Text));

            if (validName && validPath)
            {
                _inbox.folder = txtFilePath.Text;
                _inbox.setConcreteInboxName(textBoxName.Text);
                this.Dispose();
            }
            else
            {
                MessageBox.Show("Por favor ingrese una ubicación y/o nombre válidos.");
            }
        }

        private void labelName_Click(object sender, EventArgs e)
        {

        }

    }
}
